﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace A1
{
    class MainMenu
    {
        private KeyboardState keyboard; // The keyboard state
        private GamePadState gamePad1; // The gamepad state
        //private Game1.GameState mode;
        private SpriteFont font; // The game font
        private string difficultyString; // The difficulty string to draw
        private Vector2 titlePos; // The position of the title on the screen
        private Vector2 difficultyPos; //The position of the difficulty on the screen
        private InputManager input; //The inputmanager
        private string modeString; // The string stating the mode we're using
        private Vector2 modePos; //The position of the mode text
        private Vector2 descriptionPos; //The position of the game's description text

        /// <summary>
        /// Create a new main menu
        /// </summary>
        /// <param name="font">The game font</param>
        /// <param name="Input">The inputmanager object</param>
        public MainMenu(SpriteFont font, InputManager Input)
        {
            descriptionPos = new Vector2(50, 250);
            difficultyPos = new Vector2(75, 200);
            titlePos = new Vector2(20, 20);
            input = Input;
            difficultyString = "Medium";
            this.font = font;
            modePos = new Vector2(250, 400);
            modeString = "Elimination (Four Player)";
        }

        /// <summary>
        /// Update the main menu
        /// </summary>
        /// <param name="difficulty">The base difficulty of the game</param>
        /// <param name="mode">The base mode of the game</param>
        /// <returns>The next gamestate to enter</returns>
        public Game1.GameState Update(ref Game1.Difficulty difficulty, ref Game1.GameState mode)
        {
            keyboard = Keyboard.GetState();
            gamePad1 = GamePad.GetState(PlayerIndex.One);

            if (input.ButtonReady(Buttons.Start, 0) || input.KeyReady(Keys.Enter))
            {
                return Game1.GameState.Setup;
            }
            if (input.ButtonReady(Buttons.DPadDown, 0) || input.KeyReady(Keys.Down))
            {
                if ((int)difficulty == 0)
                {
                    difficulty = Game1.Difficulty.Hard;
                }
                else
                {
                    difficulty = (Game1.Difficulty)((int)difficulty - 1);
                }
            }
            else if (input.ButtonReady(Buttons.DPadUp, 0) || input.KeyReady(Keys.Up))
            {
                if ((int)difficulty == 2)
                {
                    difficulty = Game1.Difficulty.Easy;
                }
                else
                {
                    difficulty = (Game1.Difficulty)((int)difficulty + 1);
                }


            }

            if (input.ButtonReady(Buttons.DPadLeft, 0) || input.KeyReady(Keys.Left) || input.ButtonReady(Buttons.DPadRight, 0) || input.KeyReady(Keys.Right))
            {
                /*
                if (mode == Game1.GameState.TwoPlayer)
                {
                    mode = Game1.GameState.FourPlayerElimination;
                    modeString = "Elimination (Four Player)";
                }
                else if (mode == Game1.GameState.FourPlayerElimination)
                {
                    mode = Game1.GameState.TwoPlayer;
                    modeString = "Pong (Two Player)";
                }
                 */
            }
            switch (difficulty)
            {
                case Game1.Difficulty.Easy:
                    difficultyString = "Easy";
                    break;
                case Game1.Difficulty.Medium:
                    difficultyString = "Medium";
                    break;
                case Game1.Difficulty.Hard:
                    difficultyString = "Hard";
                    break;
            }
            return Game1.GameState.Main;
        }

        /// <summary>
        /// Draw the main menu
        /// </summary>
        /// <param name="spriteBatch">the spritebatch object</param>
        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.DrawString(font, "Super Board Master 4", titlePos, Color.White);
            spriteBatch.DrawString(font, difficultyString, difficultyPos, Color.White);
            spriteBatch.DrawString(font, modeString, modePos, Color.White);
            spriteBatch.DrawString(font, "Press up and down to select a difficulty", descriptionPos, Color.White);
        }
    }
}
